#coding=utf-8

#用于检验大盘和平均线的关系
from stockdb.misc import *
import strategy.avg as avg
import strategy.basic as basic
import pickle

tds = szzs.tds_since('2006-01-01')

tf = basic.TDFilter(tds)
tds2 = tf.filter_by(avg.avg_filter).all()
print len(tds2)/float(len(tds))

fragments = []
fragment = []
i = -1

print '开始shotgun.'

while True:

    if len(tds2) == 0:break
    t = tds2.pop(0)
    
    if i < 0: 
        i = tds.index(t)
        fragment.append(t)        
    else:
        i = i + 1
        t2 = tds[i]
        if t == t2:
            fragment.append(t)
        else:
            #间断了
            fragments.append(fragment)
            print len(fragments)
            fragment = []
            i = -1
            tds2.insert(0, t)
    
for f in fragments:
    print f
    
f = open('/home/jay/dp.pk' , 'w')
pickle.dump(fragments, f)
